<template>
	<view class="error-box">
		<u-image width="280rpx" height="280rpx" src="@/static/image/error.png"></u-image>
		<view class="error-tips">
			{{ tips }}
		</view>
		<view class="btn-box">
			<u-button class="btn-item" size="medium" type="primary" plain @click="handleToBack">刷新</u-button>
			<u-button class="btn-item" size="medium" type="success" plain @click="handleToIndex">回到首页</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		methods: {
			handleToBack() {
				const pages = getCurrentPages()
				if (pages.length > 2) {
					this.$u.route({
						type: 'reLaunch',
						url: `/${pages[pages.length - 2].route}`,
						params: pages[pages.length - 2].options
					})
				} else {
					this.handleToIndex()
				}
			},
			handleToIndex() {
				uni.reLaunch({
					url: '/pages/home/index'
				})
			}
		},
		data(){
			return {
				tips:'服务器开小差了~'
			}
		},
		onLoad(options){
			if(options.tips){
				this.tips = options.tips
			}
		}
	}
</script>

<style lang="scss" scoped>
	.error-box {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 200rpx 0;

		.error-tips {
			margin: 60rpx 0;
			font-size: 28rpx;
			color: #8993A4;
		}

		.btn-box {
			.btn-item {
				&:first-child {
					margin-right: 20rpx;
				}
			}
		}
	}
</style>
